package thread.wait_notify_insert_test;

/**
 * Created by mHandler on 2018/6/2 0002.
 * Description:等待/通知实现线程交叉执行
 */
public class DBTools {

    volatile private boolean prevIsA = false;

    synchronized public void backupA(){

        try {
            while (prevIsA == true){
                wait();
            }
            for (int i = 0 ;i < 5; ++i){
                System.out.println("======");
            }
            prevIsA = true;
            notifyAll();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    synchronized public void backupB(){
        try {
            while (prevIsA == false){
                wait();
            }
            for (int i = 0;i < 5;++i){
                System.out.println("+++++");
            }
            prevIsA = false;
            notifyAll();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
